from zope.interface import implements, Interface

#from Products.Five import BrowserView
from Products.CMFCore.utils import getToolByName

from my315ok.fangcan import fangcanMessageFactory as _
from my315ok.fangcan.browser.fangcansearchview import fangcansearchView


class Ihouse_listingView(Interface):
    """
    house_listing view interface
    """

    def test():
        """ test method"""


class house_listingView(fangcansearchView):
    """
    house_listing browser view
    """
    implements(Ihouse_listingView)
#    from Products.CMFCore.utils import getToolByName


    def query(self):
        """
        compose query string
        """
        cat = getToolByName(context, 'portal_catalog')
        aq = cat.makeAdvancedQuery({'meta_type' : 'house', 'review_state' : 'published'})


        if "SearchableText" in self.request.form.keys():
            term = self.request.form["SearchableText"]
            term = term.strip()
            if len(term)!=0:
                query = EQ("SearchableText",term) | Eq('Description',term)
                return query
        else:
            
            return aq
                
        raw = self.request["QUERY_STRING"]
        if len(raw) != 0:
            st = raw.split("=")
            pa = st[0]
            val = st[-1]
            
            if "-" in val:
#                op = Between
                low = val.split("-")[0]
                hight = val.split("-")[-1]
                query = Between(pa,low,hight)
                
            else:
#                op = Eq
                query = Eq(pa, val)
            return query
    def getImage(self,brain):
        tag = "/image_tile"
        base = self.getURL()
        htmltag = base + tag
        return htmltag
        
